package com.zkzx.company.base.controller;

import com.zkzx.common.company.model.CompanyDriverVO;
import com.zkzx.common.driver.param.DriverFilterParam;
import com.zkzx.common.driver.vo.DriverStatisticsVO;
import com.zkzx.common.vo.PageResult;
import com.zkzx.common.vo.RequestFilterParams;
import com.zkzx.company.base.service.CompanyDriverService;
import com.zkzx.util.json.JSONResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/10/15:26
 * @Description:
 */

@RestController
@Validated
@Api( tags="企业司机管理")
@RequestMapping(value = "/company_drivers")
public class CompanyDriverController {

    @Autowired
    private CompanyDriverService companyDriverService;

    @PostMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "增加企业司机中间表信息", notes = "增加企业司机中间表信息")
    public void add(@RequestBody CompanyDriverVO companyDriverVO) {
        companyDriverService.add(companyDriverVO);
    }

    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取企业id", notes = "获取企业id")
    public PageResult<CompanyDriverVO> find(@RequestParam("filterParam") String filterParamJson,
                                            @RequestParam("params") String paramsJson){

        DriverFilterParam filterParam = (DriverFilterParam) JSONResultUtil.toObject(filterParamJson, DriverFilterParam.class);
        RequestFilterParams params = (RequestFilterParams) JSONResultUtil.toObject(paramsJson, RequestFilterParams.class);

        return companyDriverService.find(filterParam,params);
    }

    @GetMapping("/company_driver")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取关联企业信息", notes = "获取关联企业信息")
    public List<CompanyDriverVO> getByIdCompanyId(@RequestParam("driver_id")Integer driverId,  @RequestParam("company_id")Integer companyId)  {

        return companyDriverService.getByDriverIdAndCompanyId( driverId,companyId);
    }

    @PutMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "更新中间表", notes = "更新中间表")
    public void  update(@RequestBody @Valid CompanyDriverVO companyDriverVO)  {
        companyDriverService.update(companyDriverVO);
    }

    @GetMapping("/statistics")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取司机数量信息", notes = "获取司机数量信息")
    public DriverStatisticsVO getDriverStatistics(@RequestParam("company_id")Integer companyId)  {

        return companyDriverService.getDriverStatistics( companyId);
    }





}
